﻿using System;
using System.Collections.Generic;
using System.Text;
using Com.ContentRendering.Api.RenderEngine;
using System.Xml;

namespace Com.ContentRendering.Api.RenderEngineComponentTest.Helper
{
    internal class InputNodeHelper : InputNodeInterface
    {
        XmlNode _xmlNode;

        internal InputNodeHelper(XmlNode xmlNode)
        {
            this._xmlNode = xmlNode;
        }

        public bool IsContent()
        {
            return (this._xmlNode.Name == "content");
        }

        public bool IsOutputTag()
        {
            return (
                this._xmlNode.Name == "tagRootOutput" ||
                this._xmlNode.Name == "tagChildOutput" ||
                this._xmlNode.Name == "tagParentOutput");
        }

        public bool IsSubstitutionTag()
        {
            return (
                this._xmlNode.Name == "tagRootSubstitution" ||
                this._xmlNode.Name == "tagChildSubstitution" ||
                this._xmlNode.Name == "tagParentSubstitution");
        }

        public bool IsTransparentTag()
        {
            return (
                this._xmlNode.Name == "tagRootTransparent" ||
                this._xmlNode.Name == "tagChildTransparent" ||
                this._xmlNode.Name == "tagParentTransparent");
        }

        public bool IsIfTag()
        {
            return (
                this._xmlNode.Name == "tagRootIf" ||
                this._xmlNode.Name == "tagChildIf" ||
                this._xmlNode.Name == "tagParentIf");
        }

        public bool IsIfNotTag()
        {
            return (
                this._xmlNode.Name == "tagRootIfNot" ||
                this._xmlNode.Name == "tagChildIfNot" ||
                this._xmlNode.Name == "tagParentIfNot");
        }

        public bool IsParentTag()
        {
            return (
                this._xmlNode.Name == "tagParentSubstitution" ||
                this._xmlNode.Name == "tagParentIf" ||
                this._xmlNode.Name == "tagParentIfNot" ||
                this._xmlNode.Name == "tagParentOutput");
        }

        public bool IsChildTag()
        {
            return (
                this._xmlNode.Name == "tagChildSubstitution" ||
                this._xmlNode.Name == "tagChildIf" ||
                this._xmlNode.Name == "tagChildIfNot" ||
                this._xmlNode.Name == "tagChildOutput");
        }

        public bool IsRootTag()
        {
            return (
                this._xmlNode.Name == "tagRootSubstitution" ||
                this._xmlNode.Name == "tagRootIf" ||
                this._xmlNode.Name == "tagRootIfNot" ||
                this._xmlNode.Name == "tagRootOutput");
        }

        public string Name
        {
            get { return this._xmlNode.Attributes["name"].Value; }
        }

        public int ParentLevel
        {
            get { return int.Parse(this._xmlNode.Attributes["level"].Value); }
        }

        public string Content
        {
            get { return this._xmlNode.InnerText; }
        }

        public IEnumerator<InputNodeInterface> FetchChildNodes()
        {
            List<InputNodeInterface> inputNodeHelpers = new List<InputNodeInterface>();

            foreach (XmlNode xmlNode in this._xmlNode.ChildNodes)
            {
                inputNodeHelpers.Add(new InputNodeHelper(xmlNode));
            }

            return inputNodeHelpers.GetEnumerator();
        }
    }
}
